package com.jsd2412.backend.meals.controller;

import com.jsd2412.backend.base.response.JsonResult;
import com.jsd2412.backend.meals.pojo.dto.MealSaveParam;
import com.jsd2412.backend.meals.pojo.dto.MealsQueryParam;
import com.jsd2412.backend.meals.pojo.vo.MealsVO;
import com.jsd2412.backend.meals.service.MealsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/meals")
public class MealsController {
    @Autowired
    private MealsService mealsService;

    @GetMapping("/select")
    public JsonResult selectMeals(MealsQueryParam mealsQueryParam) {
        log.debug("查询膳食维护业务:{}", mealsQueryParam);
        List<MealsVO>  list=mealsService.select(mealsQueryParam);
        log.debug("查询膳食维护业务结果:{}", list);
        return  JsonResult.ok(list);
    }

    @PostMapping("/save")
    public JsonResult saveMeals(MealSaveParam mealSaveParam) {
        log.debug("保存膳食维护业务:{}", mealSaveParam);
        mealsService.save(mealSaveParam);
        return  JsonResult.ok();
    }

    @PostMapping("/delete/{id}")
    public JsonResult deleteMeals(@PathVariable Long id) {
        log.debug("删除膳食维护业务:{}", id);
        mealsService.delete(id);
        return  JsonResult.ok();
    }


}
